<template>
  <el-dialog
    title="增加乐骑卫士管理员"
    width="50%"
    :visible.sync="visible"
    @close="$emit('update:show', false)"
    :show="show"
  >
    <el-form :model="formInline"  label-width="80px" label-position="left" :rules="rules" ref="updateUser">
      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item label="姓名" prop="userName">
            <el-input v-model="formInline.userName" placeholder="姓名"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="手机号" prop="telephone">
            <el-input v-model="formInline.telephone" placeholder="登录账号"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <span slot="footer" class="dialog-footer">
    <el-button @click="close('updateUser')">取 消</el-button>
    <el-button type="primary" @click="sure('updateUser')">确 定</el-button>
  </span>
  </el-dialog>
</template>

<script>
  import ShowMadal from '@/mixins/showmadal'
  import {validatePhone} from '@/utils/validate'
  export default {
    name: 'Updateuser',
    mixins: [ShowMadal],
    data: function() {
      var checkPhone = (rule, value, callback) => {
        if (!validatePhone(value)) {
          return callback(new Error('请填写正确的手机号'))
        }else {
          callback()
        }
      }
      return {
        formInline: {},
        rules: {
          userName: [
            { required: true, message: '请输入姓名', trigger: 'blur' }
          ],
          telephone: [
            { required: true, message: '请输入手机号', trigger: 'blur' },
            { type: 'number', validator: checkPhone, trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      sure(formName) {
        this.$emit('submit', {formName: this.$refs[formName], formInline: this.formInline})
      },
      close(formName) {
        this.$emit('close', this.$refs[formName])
      }
    }
  }
</script>

<style scoped>

</style>
